package org.veloxbot.api.internals.concurrent;

import org.veloxbot.api.utils.UUID;
import org.veloxbot.api.utils.Random;

/**
 * @author Velox
 */
public abstract class Task extends Thread implements Runnable {

	/**
	 * What to do when the Task is executed.
	 */
	public abstract void run();

	/**
	 * The Task's identidy.
	 */
	protected final int id;

	public Task() {
		id = UUID.generate();
	}

	/**
	 * Checks if the Task is equal to another Task.
	 *
	 * @param object The object to compare the Task to.
	 * @return Whether or not the Task and object are equal.
	 */
	@Override
	public boolean equals(final Object object) {
		return object instanceof Task && ((Task) object).id == id;
	}

	/**
	 * Sleeps for the given amount of time.
	 *
	 * @param millis The amount of time to sleep for.
	 */
	public static void sleep(final int millis) {
		try {
			Thread.sleep(millis);
		} catch (final InterruptedException ignored) {
		}
	}

	/**
	 * Sleeps for a random amount of time between the given parameters.
	 *
	 * @param min The minimum amount of time to sleep for.
	 * @param max The maximum amount of time to sleep for.
	 */
	public static void sleep(final int min, final int max) {
		sleep(Random.nextInt(min, max));
	}
}
